package com.yuanxiao.common.api.feign;

import com.yuanxiao.common.api.entity.SysLogEntity;
import com.yuanxiao.common.api.feign.fallback.SysServerFeignFallbackClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import com.yuanxiao.common.core.result.R;

import java.util.List;
import java.util.Set;

//@FeignClient(value = "lzsh-system", fallback = SysLogFeignFallbackClient.class)
@FeignClient(value = "lzsh-system", url = "http://localhost:53021", fallback = SysServerFeignFallbackClient.class)
@Qualifier("sysServerFeignClient")
public interface SysServerFeignClient {

    @PostMapping("/sys/log/save")
    R saveLog(@RequestBody SysLogEntity log);

    @GetMapping("/sys/user/info/{userId}")
    R getUserByUserId(@PathVariable("userId") Long userId);

    @GetMapping("/sys/user/info/{userId}")
    R getUserByUserId(@PathVariable("userId") Long userId, @RequestParam("serverRequest") String serverRequest);

    @PostMapping("/sys/user/check/handlepwd/{userId}/{handlePwd}")
    R checkHandlepwd(@PathVariable("userId") Long userId, @PathVariable("handlePwd") String handlePwd);

    @GetMapping("/sys/dept/info/{deptId}")
    R getDeptById(@PathVariable("deptId") Long deptId);

    /**
     * 根据部门ids获取部门名称（逗号拼接）
     * @param idsList ids
     */
    @PostMapping("/sys/server-call/dept/query/names/by/ids")
    R getDeptNamesByIds(@RequestBody List<Long> idsList);


    @PostMapping("/sys/server-call/dept/info/{deptId}")
    R getDeptInfo(@PathVariable("deptId") Long deptId);

    @PostMapping("/sys/server-call/dept/info/{tenantCode}/{deptCode}")
    R getDeptInfo(
            @PathVariable("tenantCode") String tenantCode,
            @PathVariable("deptCode") String deptCode);

    @PostMapping("/sys/server-call/dept/tenant/info/{tenantId}")
    R getTenantInfo(
            @PathVariable("tenantId") Long tenantId);

    @GetMapping("/sys/server/call/feign/cfg/handel/list")
    R handelFeignCallList(
            @RequestParam("serverCode") String serverCode,
            @RequestParam("usedType") String usedType,
            @RequestParam("bizCode") String bizCode
    );

    /**
     * 区域字典查询
     */
    @GetMapping("/sys/server-call/dic/area/info/{areaCode}")
    R getDicArea(@PathVariable("areaCode") String areaCode);

    /**
     * 区域字典查询
     */
    @PostMapping("/sys/server-call/dic/area/list/batch/of/codeList")
    R getDicAreaBatchByCodeList(
            @RequestBody List<String> areaCodeList
    );

    /**
     * 根据租户id和字典编码获取字典信息
     * @param tenantId 租户ID
     * @param dicCode 字典编码
     * @return R -> data: DicGeneralEntity
     */
    @GetMapping("/sys/server-call/dic/general/info/{tenantId}/{dicCode}")
    R getDicGeneralInfo(@PathVariable("tenantId") Long tenantId, @PathVariable("dicCode") String dicCode);

    /**
     * 根据租户id和字典父级编码获取字典列表信息
     * @param tenantId
     * @param parentCode
     * @return R -> data: List<DicGeneralEntity>
     */
    @GetMapping("/sys/server-call/dic/general/list/{tenantId}/{parentCode}")
    R getDicGeneralList(@PathVariable("tenantId") Long tenantId, @PathVariable("parentCode") String parentCode);

    /**
     * 根据 Set<String> dicCodes 查询对应的字典，返回 Map<String, DicGeneralEntity>
     * @param dicCodes 字典编码集合
     * @return R -> data: Map<String, DicGeneralEntity>
     */
    @PostMapping("/sys/server-call/dic/general/list/{tenantId}/queryDicGeneralByDicCodes")
    R queryDicGeneralByDicCodes (@PathVariable("tenantId") Long tenantId, @RequestBody Set<String> dicCodes);

    /**
     * 根据deptId、merchantType 获取商户信息
     * @param merchantType 商户类型, 如：LAKALA, WECHAT, ALIPAY
     * @param deptId 机构ID
     * @return
     */
    @GetMapping("/sys/server-call/merchant/info/{merchantType}/{deptId}")
    R getByDeptIdAndMerchantType(
            @PathVariable("merchantType") String merchantType,
            @PathVariable("deptId") Long deptId
    );
}
